<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 100px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div>

    </div>
    <script>
        let div = document.querySelector('div')
        div.addEventListener('mouseenter',()=>{
            let ajx = new XMLHttpRequest()
            ajx.open('post','http://127.0.0.1:9800/serve/setpost')
            // ajx.responseType='json'   把请求数据设置为json数据
            // ajx.setRequestHeader(key,value)  设置请求头
            ajx.send('zhangsan')
            ajx.onreadystatechange = function(){
                if (ajx.readyState === 4) {
                    if (ajx.status==200) {
                        
                        // console.log(typeof ajx.response);
                       let obj =  JSON.parse(ajx.response);
                       let getHtml = '';
                       for (const key in obj) {
                         var p =   document.createElement('p')
                         p.innerHTML = obj[key]
                         div.appendChild(p)   
                        //  getHtml += obj[key]+`<br>`
                       }
                    //    let array = Object.values(obj)
                    //    let getHtml = ''
                    //    array.forEach(element => {
                    //        div.innerHTML = element+`<br>`
                    //        getHtml += `<span>${element}</span><br>`
                    //    });
                    
                    }
                }
            }
        })
    </script>
</body>

</html>